﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VisionCloud.Core.Model.Ms;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Schedule.ProjectInfo;
using VisionCloud.Domain.Repository.Interface.Ms;

namespace VisionCloud.Service.Schedule
{
    public class ScheduleProjectService
    {
        public IMsProjectRepository ProjectRepository { get; set; }
        public IMapper Mapper { get; set; }
        public List<ScheduleProjectLocaltionDto> GetLocaltionList()
        {
            var result = ProjectRepository.GetAll()
                .Where(x => x.IsDeleted == false && x.PubliceDate != null)
                .Select(x => new ScheduleProjectLocaltionDto
                {
                    Id = x.ProjectId,
                    Longitude = x.Longitude,
                    Latitude = x.Latitude,
                    ProjectName = x.Name
                }).ToList();
            return result;
        }

        public ScheduleProjectDetailDto GetProjectDetail(Guid id)
        {
            var result = ProjectRepository.GetById(id);
            if (result == null)
            {
                throw new OperationException($"项目{id}不存在");
            }

            var data = Mapper.Map<MsProject, ScheduleProjectDetailDto>(result);
            return data;
        }
    }
}
